package com.xianyun.smartpicturebackend.exception;

import com.xianyun.smartpicturebackend.common.BaseResponse;
import com.xianyun.smartpicturebackend.common.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/** 自定义全局异常处理器
 * @author xianYun
 * @version 1.0
 **/
@RestControllerAdvice
@Slf4j
public class GlobalException {
    /**
     * 处理自定义异常的处理器
     * @param e
     * @return
     */
    @ExceptionHandler({BusinessException.class})
    public BaseResponse<?> businessExceptionHandler(BusinessException e) {
        log.error("businessExceptionHandler=====>", e);
        return ResultUtils.error(e.getCode(),e.getMessage());
    }

    @ExceptionHandler({RuntimeException.class})
    public BaseResponse<?> runtimeExceptionHandler(RuntimeException e) {
        log.error("runtimeExceptionHandler=====>", e);
        return ResultUtils.error(ErrorCode.SYSTEM_ERROR);
    }
}
